﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAL
{
    public partial class User
    {
        public static User[] GetAllUsers()
        {
            using (DataAccessDataContext dc = new DataAccessDataContext())
            {
                var result = from user in dc.Users
                             select user;
                return result.ToArray<User>();
            }
        }

        public static void AddUser(User user)
        {
            using (DataAccessDataContext dc = new DataAccessDataContext())
            {
                dc.Users.InsertOnSubmit(user);
                dc.SubmitChanges();
            }
        }

        public static User GetUserByEmail(String email)
        {
            using (DataAccessDataContext dc = new DataAccessDataContext())
            {
                var result = from user in dc.Users
                             where user.email == email
                             select user;
                return result.Single<User>();
            }
        }
    }
}
